import { defineStore } from 'pinia'
import {UserInfo} from "common";
import {ref} from "vue";


export const useRootStore = defineStore('root',
    () => {


        const userInfo = ref<UserInfo | null>(null);

        const Cookie = ref<string>('')
        const updateUserInfo = (newUserInfo: UserInfo | null) => {
            userInfo.value = newUserInfo;
        }

        const updateCookie = (cookie:string)=>{
            Cookie.value=cookie;
        }

        return {
            Cookie,
            userInfo, // 并没有做userInfoPromise这样的属性，如果要等userInfo有值之后做某些操作的话，应该在组件内用“ watch(useInfo,() => {}) ”这样的形式
            updateUserInfo,
            updateCookie
        }
    }
)

